<?php

class Accessibility
{
    private $noName = 'name will not be seen';

    private function notSeen()
    {
        return 'method can not be invoked';
    }
}

$obj = new Accessibility();

$reflection = new ReflectionClass($obj);

// 修改private属性,此处的no_name是属性名，不可用变量名
$property = $reflection->getProperty('noName');
$property->setAccessible(true);
echo $property->getValue($obj) . PHP_EOL;

// 修改private属性的值为可读
$property->setValue($obj, 'name can be seen');
echo $property->getValue($obj) . PHP_EOL;

// 修改private方法为可访问
$method = $reflection->getMethod('notSeen');
$method->setAccessible(true);
echo $method->invoke($obj);
